package unit12;
public class demo02 {
    public static void main(String[] args) {
        final Object lock = new Object();

        Thread student1 = new Thread(() -> {
            try {
                synchronized (lock) {
                    lock.wait(10 * 60 * 1000); // Wait for 10 minutes
                }
                System.out.println("Student 1: Ready!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread student2 = new Thread(() -> {
            try {
                Thread.sleep(60 * 60 * 1000); // Sleep for 1 hour
                synchronized (lock) {
                    System.out.println("Student 2: Ready!");
                    lock.notify(); // Notify teacher thread
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread teacher = new Thread(() -> {
            synchronized (lock) {
                try {
                    for (int i = 0; i < 3; i++) {
                        System.out.println("Teacher: Class starts!");
                        Thread.sleep(1000); // Wait for 1 second
                    }

                    // Teacher wakes up student1
                    System.out.println("Teacher: Wake up Student 1!");
                    lock.notify(); // Notify student1 thread
                    lock.wait(); // Wait for student1 to be ready
                    System.out.println("Teacher: Student 1 is awake!");

                    // Teacher wakes up student2
                    System.out.println("Teacher: Wake up Student 2!");
                    student2.start();
                    lock.wait(); // Wait for student2 to be ready
                    System.out.println("Teacher: Student 2 is awake!");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        teacher.start();
        student1.start();
    }
}